﻿using System.Globalization;
using Google.Analytics.Web.Converters;
using NUnit.Framework;

namespace Google.Analytics.WebTests
{
    public class CSVConverterTests : ConverterTestBase<CSVConverter, string>
    {
        [Test]
        public void ConvertFromSingle()
        {
            var expected = new[] {"one"};
            var result = Converter.ConvertFrom(GetTypeContext(), CultureInfo.CurrentCulture, "one");
            VerifyConverFromResult(result, expected);
        }

        [Test]
        public void ConvertFromMultiple()
        {
            var expected = new[] { "one", "two" };
            var result = Converter.ConvertFrom(GetTypeContext(), CultureInfo.CurrentCulture, "one,two");
            VerifyConverFromResult(result, expected);
        }

        [Test]
        public void ConvertFromMultipleSpace()
        {
            var expected = new[] { "one", "two" };
            var result = Converter.ConvertFrom(GetTypeContext(), CultureInfo.CurrentCulture, "one, two");
            VerifyConverFromResult(result, expected);
        }

        [Test]
        public void ConvertFromMultipleExtraComma()
        {
            var expected = new[] { "one", "two" };
            var result = Converter.ConvertFrom(GetTypeContext(), CultureInfo.CurrentCulture, "one,two,");
            VerifyConverFromResult(result, expected);
        }

        [Test]
        public void ConvertFromEmpty()
        {
            var expected = new string[] {};
            var result = Converter.ConvertFrom(GetTypeContext(), CultureInfo.CurrentCulture, "");
            VerifyConverFromResult(result, expected);
        }

        [Test]
        public void ConvertFromSingleComma()
        {
            var expected = new string[] { };
            var result = Converter.ConvertFrom(GetTypeContext(), CultureInfo.CurrentCulture, ",");
            VerifyConverFromResult(result, expected);
        }

        [Test]
        public void ConvertToSingle()
        {
            var actual = new[] { "one" };
            var result = Converter.ConvertTo(GetTypeContext(), CultureInfo.CurrentCulture, actual, typeof(string));
            VerifyCovnertToResult(result, "one");
        }

        [Test]
        public void ConvertToMultiple()
        {
            var actual = new[] { "one", "two" };
            var result = Converter.ConvertTo(GetTypeContext(), CultureInfo.CurrentCulture, actual, typeof(string));
            VerifyCovnertToResult(result, "one,two");
        }

        [Test]
        public void ConvertToMultipleEmpty()
        {
            var actual = new[] { "one", "two", "" };
            var result = Converter.ConvertTo(GetTypeContext(), CultureInfo.CurrentCulture, actual, typeof(string));
            VerifyCovnertToResult(result, "one,two");
        }
    }
}
